/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package todotask.Adapters;

import java.awt.event.MouseAdapter;
import java.awt.event.MouseEvent;
import java.util.Calendar;
import todotask.Database.Data;
import todotask.entities.Category;
import todotask.entities.Status;
import todotask.entities.Task;
import todotask.view.TaskProperties;

/**
 *
 * @author dakota
 */
public class SaveTaskAdapter extends MouseAdapter {

    private TaskProperties t;
    private Data d = new Data();

    public SaveTaskAdapter(TaskProperties nt) {
        this.t = nt;
    }

    @Override
    public void mouseClicked(MouseEvent me) {
        //Guardar Tarea
        System.out.println("Title: " + t.getTitleTask().getText());
        System.out.println("Description: " + t.getDescriptionTask().getText());
        System.out.println("Category: " + t.getListCategory().getSelectedItem());
        System.out.println("Status: " + t.getListStatus().getSelectedItem());
        System.out.println("Start Date: " + Calendar.getInstance().getTime());
        System.out.println("Finish Date: " + Calendar.getInstance().getTime());

        Task task = new Task();
        task.setTitle(t.getTitleTask().getText());
        task.setDescription(t.getDescriptionTask().getText());
        task.setStatus((Status) t.getListStatus().getSelectedItem());
        task.setCategory((Category) t.getListCategory().getSelectedItem());

        if (!d.saveTask(task)) {
            //Llamar al gestor de errores
        }else{
            t.dispose();
        }

    }
}
